package com.student.demo.service.impl;

import com.student.demo.dao.LoginDao;
import com.student.demo.dao.StudentDao;
import com.student.demo.entiy.LoginResult;
import com.student.demo.entiy.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginService implements com.student.demo.service.LoginService {
    @Autowired
    private LoginDao loginDao;


    @Override
    public LoginResult verify(User user) {

        String tip = "用户名错误";
        boolean isLogin = false;
        LoginResult result = new LoginResult();
        List<User> userList = loginDao.queryUser();
        for (int i = 0; i < userList.size(); i++) {
            if(userList.get(i).getUserName().equals(user.getUserName())) {
                if(userList.get(i).getPassword().equals(user.getPassword())) {
                    isLogin = true;
                    tip = "成功";
                }
                else
                    tip = "密码错误";
            }
        }
        result.isLogin = isLogin;
        result.tip = tip;
        return result;
    }

    @Override
    public void register(User user) {
        loginDao.register(user.getUserName(), user.getPhoneNumber(), user.getPassword());
    }
}
